package com.guigu.tms.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.guigu.tms.commons.user.entity.Member;
import com.guigu.tms.user.service.IMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.commons.util.IdUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author zwj
 * @since 2022-10-16
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    private IMemberService memberService;

    //获取用户信息
    @GetMapping("getMemberById/{id}")
    public Member getMemberById(@PathVariable("id") String id){
        return memberService.getById(id);
    }

    @PostMapping("createMember")
    public Member createMember (@RequestBody Member member){
        System.out.println(member);
        QueryWrapper<Member> wrapper = new QueryWrapper<>();
        wrapper.eq("phone",member.getPhone());
        Member m = memberService.getOne(wrapper);
        if(m==null){
            member.setId(IdWorker.getId()+"");
            memberService.save(member);
            return member;
        }else {
            return m;
        }
    }

}
